﻿package {
	import flash.display.MovieClip;
	
	public class Rabbit extends MovieClip{
		public var state:int=0;
		var runState:int=0;
		//const stateTable:Array=new Array(new Array(1,1,6),new Array(2,7,14),new Array(3,15,18),new Array(4,19,22),new Array(5,23,23),new Array(6,24,24),new Array(7,25,25),new Array(8,26,26),new Array(9,27,29));
		const stateTable:Array=new Array(new Array(1,6),new Array(7,14),new Array(15,18),new Array(19,22),new Array(23,23),new Array(24,24),new Array(25,25),new Array(26,26),new Array(27,29));
		//0站立，1走，2跑，3快跑，4跳，5下落，6受伤，7坐倒，8晕
		public var oldY:Number;
		var stepY:Number=0;
		var frame:int=1;
		public function Rabbit():void{
			setState(0);
			stepY=0;
		}
		public function setState(s:int):void{
			if (s==state){
				return;
			}else if(s==4){
				stepY=-12;
			}else if(s<4){
				runState=s;
			}
			frame=1;
			state=s;
			this.gotoAndStop(stateTable[s][0]);
			
		}
		public function setRunState(s:int):void{
			runState=s;
		}
		public function floor():void{
			stepY=0;
			if (state==5){
				setState(runState);
			}
		}
		public function everyFrame():void{
			stepY+=0.7;
			if(stepY>2){
				setState(5);
			}
			oldY=this.y;
			this.y+=stepY;
			if (this.y>20){
			}
			if(frame++==2){
				this.nextFrame();
				frame=1;
			}
			if (this.currentFrame>stateTable[state][1]){
				this.gotoAndStop(stateTable[state][0]);
			}
		}
	}
}